package com.jiangxiaofei.citycloud.mvp;

import android.content.Context;

import com.jiangxiaofei.citycloud.bean.BaiduPlaceBean;
import com.jiangxiaofei.citycloud.bean.ParkBean;
import com.jiangxiaofei.citycloud.bean.ParkDetailInfoBean;
import com.jiangxiaofei.citycloud.httpUtil.APIUrl;
import com.jiangxiaofei.citycloud.httpUtil.OnLoadDataIm;
import com.jiangxiaofei.citycloud.httpUtil.RetrofitUtils;
import com.jiangxiaofei.citycloud.param.BaiduPlaceParam;
import com.jiangxiaofei.citycloud.param.GetPartParam;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 作者: JiangXfei
 * 日期: 2017/9/20 0020
 */

public class CarModel implements CarConstant.GetBaiduPlaceModel, CarConstant.GetParkModel, CarConstant.getParkDetailModel {

    //    获取百度place
    @Override
    public void setBaiduPlace(Context mContext, BaiduPlaceParam baiduPlaceParam, final OnLoadDataIm callback) {
        RetrofitUtils.getApiService(mContext, APIUrl.BAIDU_PLACE_URL).getBaiduPlace(baiduPlaceParam.getQ()
                , baiduPlaceParam.getRegion(), baiduPlaceParam.getOutput(), baiduPlaceParam.getAk())
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaiduPlaceBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(BaiduPlaceBean baiduPlaceBean) {
                        if (baiduPlaceBean.getMessage().equals("ok")) {
                            callback.onSuccess(baiduPlaceBean.getResults(), baiduPlaceBean.getMessage(), baiduPlaceBean.getStatus());
                        }
                    }
                });
    }

    @Override
    public void getPark(Context mContext, GetPartParam partParam, final OnLoadDataIm callback) {
        RetrofitUtils.getApiService(mContext, APIUrl.PARK_URL)
                .getPark(partParam.getLng(), partParam.getLat(),
                        partParam.getCity(), partParam.getIsReserve(),
                        partParam.getDisplayType(), partParam.getType(),
                        partParam.getPageSize(), partParam.getCurrentPage())
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ParkBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ParkBean partBean) {
                        if (partBean.getStatus() == 0) {
                            callback.onSuccess(partBean.getTwoKilometreParkList(), partBean.getMessage(), partBean.getStatus());
                        }
                    }
                });
    }

    @Override
    public void getPartDetail(Context mContext, String parkSeq, final OnLoadDataIm callback) {
        RetrofitUtils.getApiService(mContext, APIUrl.PARK_URL)
                .getParkInfo(parkSeq)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ParkDetailInfoBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ParkDetailInfoBean parkDetailInfoBean) {
                        if (parkDetailInfoBean.getStatus() == 0) {
                            callback.onSuccess(parkDetailInfoBean.getParkDetailsInfo(),parkDetailInfoBean.getMessage(),parkDetailInfoBean.getStatus());
                        }
                    }
                });
    }
}
